#include "menu_manager.h"

Menu_Manager :: Menu_Manager () {
	pb = new Print_Buffer ();
	scheduler = new Scheduler (pb);
	file = "input.list";
}

Menu_Manager :: ~Menu_Manager () {
	delete pb;
	delete scheduler;
}

void Menu_Manager :: run () {
	bool keep_going = true;
	int menu_option = 0;

	while (keep_going) {
		pb -> block ("Menu");
		menu_option = main_menu ();
		menu_choice (menu_option, & keep_going);	
	}

	pb -> block ("Program ran to completion!");
}

int Menu_Manager :: main_menu () {
	int result = 0;

	/* Print out current options */
	pb -> out ("Current Settings:\n");
	scheduler -> print_settings ();
	cout << "Input file: " << file << endl;
	cout << "Verbosity: " << pb -> get_verbosity () << endl;
	cout << endl;

	/* Show options the user can choose */
	cout << "Options:" << endl;
	cout << "0. Run simulation" << endl;
	cout << "1. Change scheduler and scheduling settings" << endl;
	cout << "2. Change input file" << endl;
	cout << "3. Change verbosity" << endl;
	cout << "4. Quit simulator" << endl;

	/* Get User input */
	cout << endl << "Choose input: ";
	cin >> result;
	cout << endl;

	return result;
}

void Menu_Manager :: menu_choice (int choice, bool * keep_going) {

	if (choice == 0) {
		/* Run the simulator with given settings */
		scheduler -> run (file);
	} else if (choice == 1) {
		/* Bring up the settings for the scheduling */
		menu_scheduler ();
	} else if (choice == 2) {
		/* Change input filename */
		cout << "Enter input file name: ";
		cin >> file;
		cout << endl;
	} else if (choice == 3) {
		/* Adjust verbosity settings */
		menu_verbosity ();
	} else if (choice == 4) {
		/* Quit simulator */
		* keep_going = false;
		cout << "Exiting simulator" << endl;
	} else {
		cout << "Incorrect input - try again..." << endl;
	}

	cout << endl;
}

void Menu_Manager :: menu_scheduler () {
	cout << "Current scheduler settings..." << endl;
	scheduler -> print_settings ();
	cout << endl;
	scheduler -> settings_menu ();
	cout << endl;
}

// TODO - can implement later
void Menu_Manager :: menu_verbosity () {
	cout << "verbosity settings" << endl;
	cout << endl;
}

